/*
 * Este es el panel para mostrar la imagen en el preview de imagenes y que se puedan
 * seleccionar
 */

package tp_imag.gui.components;

import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.image.BufferedImage;
import java.util.ArrayList;
import java.util.Collection;
import tp_imag.model.ImageItem;

/**
 *
 * @author gdenari
 */
public class JSelectImagePanel extends JImagePanel implements MouseListener {

    private Collection<SelectImageListener> listeners = new ArrayList<SelectImageListener>();

    private ImageItem imageItem;

    public JSelectImagePanel(BufferedImage image, int x, int y, Dimension size, ImageItem imageItem) {
        super(image, x, y, size);

        addMouseListener(this);
        this.imageItem = imageItem;
    }

    public void mouseClicked(MouseEvent e) {  
    }

    public void mousePressed(MouseEvent e) {
        for (SelectImageListener list : listeners) {
            list.imageSelected(imageItem);
        }
    }

    public void mouseReleased(MouseEvent e) {
    }

    public void mouseEntered(MouseEvent e) {
        setCursor(new Cursor(Cursor.HAND_CURSOR));
    }

    public void mouseExited(MouseEvent e) {
        setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
    }

    public void addSelectImageListener(SelectImageListener listener) {
        listeners.add(listener);
    }

    public void removeSelectImageListener(SelectImageListener listener) {
        listeners.remove(listener);
    }

}
